package com.test.selenium.util;

import java.util.List;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.io.File;
import java.util.ArrayList;

import junit.framework.TestCase;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.test.selenium.AirSmokeTest;
import com.test.selenium.data.InputTestData;
import com.test.selenium.data.OutputSheet;
import com.test.selenium.data.Results;
import com.test.selenium.data.ShipmentData;
import com.test.selenium.data.UTiLogin;


public class SmokeTestShipment extends TestCase{
	private final double epsilon = 1E-10;
	private boolean debugMode = true;	
	
	private String bookingUrl;
	private WebDriver driver;
	private SmokeTestTimeStamp timeStamp;
	private ShipmentData shipmentData;
	private OutputSheet resultSheet;
	private WebDriverWait wait;
	
	private String shipmentNumber = "";
	private String shipmentMilestone = "";
	private String complianceStatus = "";
	private String ReferenceValue = "";
	
	private String ratingStatus;
	private String invoicestatus;
	private String invoicesearchurl;
	private String invoiceviewurl;
	private String invoiceinitiateurl;
	private String correctionchargesurl;
	
	private String shippotimestamp;
	private String  potimestamp;
	
	private String invoicenumber;
	private String crinvoicenumber;
//	private List<Results> shipmentResultsArray;
	private double testTimeTakenSec;
	private String buildlabel;
	private String envname;
	private String isPass;
		
	public SmokeTestShipment(WebDriver driver, SmokeTestTimeStamp timeStamp, ShipmentData shipmentData, OutputSheet resultSheet) {
		this.driver = driver;
		this.timeStamp = timeStamp;
		this.shipmentData = shipmentData;
		this.resultSheet = resultSheet;
		bookingUrl = UTiLogin.url + "#!booking";
		wait = new WebDriverWait(driver, 60);
//        this.shipmentResultsArray = new ArrayList<Results>();
     
	}
	
//	public List<Results> getResultsArray(){
//		return this.shipmentResultsArray;
//	}

	String testStartTime = new SimpleDateFormat("MMM-dd-yyyy_HHmmss").format(new Date());
	String testEndTime = new SimpleDateFormat("MMM-dd-yyyy_HHmmss").format(new Date());
	
	public void getHeaderinfo() throws InterruptedException{
		envname =driver.findElement(By.xpath("/html/body/div/div/ul/li/div/div/ul/li/label")).getText();
		buildlabel= driver.findElement(By.className("versionNumber")).getText();
		Thread.sleep(3000);
	}
	
	public void bookShipment() {
        driver.get(bookingUrl);
        String originCode = shipmentData.getOrigin();
        String destinationCode = shipmentData.getDestination();
        String isPass ;
        //double testTimeTakenSec = 0;
        try {
	        /*Enter required data to Create Shipment(ProductCode,IncotermCode,PaymentTerm, AvailableDates,Shipper&ConsigneeParty,
	          load_port_code,export_gateway_code,discharge_port_code,import_gateway_code,customer_stated_piece_count,customer_stated_weight,customer_stated_weight_uom_code)*/
	        WebElement productCodeDropDown= wait.until(ExpectedConditions.elementToBeClickable(By.id("product_code")));
	        new Select (productCodeDropDown).selectByVisibleText(shipmentData.getProductCode());
	        new Select (driver.findElement(By.id("incoterm_code"))).selectByVisibleText(shipmentData.getIncoTermCode());
	        driver.findElement(By.id("available_local_datetime")).sendKeys(timeStamp.getArrivalDate());
	        driver.findElement(By.id("local_time_AVAILABLE")).sendKeys(timeStamp.getArrivalTime());
	        //driver.findElement(By.id("received_local_datetime")).sendKeys(timeStamp.getReceivedDate());
	        //driver.findElement(By.id("local_time_RECEIVED")).sendKeys(timeStamp.getReceivedTime());
	        //new Select (driver.findElement(By.id("payment_term_code"))).selectByVisibleText(shipmentData.getPaymentTerm());
	        new Select (driver.findElement(By.id("payment_term_code"))).selectByVisibleText("PREPAID");
            WebElement shipperField = driver.findElement(By.xpath("/html/body/div[4]/div/div/div[3]/div/div/div[2]/table/tbody/tr[2]/td[3]/input"));
            shipperField.sendKeys(shipmentData.getShipperPartyAccount());
	        shipperField.sendKeys(Keys.TAB);	//Tab out to retrieve SHIPPER Party details.
//	        Thread.sleep(5000);
//	        System.out.println("shipper account entered");
//	        wait.until(ExpectedConditions.presenceOfElementLocated(By.className("ui-widget-overlay")));
//	        System.out.println("overlay shown");
//	        wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("ui-widget-overlay_______")));
//	        System.out.println("overlay disappeared");
	        Thread.sleep(5000);
	        WebElement consigneeField = driver.findElement(By.xpath("/html/body/div[4]/div/div/div[3]/div/div/div[2]/table/tbody/tr[3]/td[3]/input"));
	        consigneeField.sendKeys(shipmentData.getConsigneePartyAccount());
	        consigneeField.sendKeys(Keys.TAB);	//Tab out to retrieve CONSIGNEE Party details.
            Thread.sleep(5000);
	        WebElement vendorField =  driver.findElement(By.xpath("/html/body/div[4]/div/div/div[3]/div/div/div[2]/table/tbody/tr[4]/td[3]/input"));
	        vendorField.sendKeys(shipmentData.getvendorPartyAccount());
	        vendorField.sendKeys(Keys.TAB);	//Tab out to retrieve vendor Party details.
	        Thread.sleep(8000);
//	        driver.findElement(By.className("roles uti_parties_sub_details_row_roles"));
//	        WebElement vendorCheckBox = driver.findElement(By.id(shipmentData.getvendorPartyAccount() + "_VENDOR"));
	        List<WebElement> roles = driver.findElements(By.className("mdmRole"));
	        for (WebElement role: roles) {
	        	if (role.getAttribute("value").equalsIgnoreCase("VENDOR")) {
	        		role.sendKeys(Keys.SPACE);
	        		break;
	        	}
	        }
	        Thread.sleep(5000);
	        driver.findElement(By.xpath("/html/body/div[4]/div/div/div[3]/div/div/div[3]/button")).click();
            driver.findElement(By.id("load_port_code")).sendKeys(shipmentData.getOrigin());
	        driver.findElement(By.id("export_gateway_code")).sendKeys(shipmentData.getOrigin());
	        driver.findElement(By.id("discharge_port_code")).sendKeys(shipmentData.getDestination());
	        driver.findElement(By.id("import_gateway_code")).sendKeys(shipmentData.getDestination());
	        driver.findElement(By.id("customer_stated_piece_count")).sendKeys(shipmentData.getBookedPieces());
	        driver.findElement(By.id("customer_stated_weight")).sendKeys(shipmentData.getBookedWeight());
	        new Select (driver.findElement(By.id("customer_stated_weight_uom_code"))).selectByVisibleText(shipmentData.getBookedWeightType());
	        //Click Save Button on Shipment UI
	        wait.until(ExpectedConditions.presenceOfElementLocated(By.className("saveLinkImage"))).click();
	        long timeBeforeSave = System.currentTimeMillis();
	        // Wait until shipment status = "B-CREATE"
	        wait.until(new ExpectedCondition<Boolean>(){
    	        @Override
    	        public Boolean apply(WebDriver d) {
    	        	return d.findElement(By.id("SHIPMENT")).getText().equalsIgnoreCase("B-CREATE");
    	    	}
	        });
	        long timeAfterSave = System.currentTimeMillis();
	        testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;
	        
	        shipmentMilestone = driver.findElement(By.id("SHIPMENT")).getText();
	        shipmentNumber = driver.findElement(By.id("shipment_number")).getAttribute("Value");
	      
	        if (debugMode) {
	        	System.out.println("Create shipment completed.");
	        	String shipmentLocation = driver.findElement(By.id("current_loc_disp")).getText();
	            //String complianceStatus = driver.findElement(By.id("COMP_DNP")).getText();
		        System.out.println("ShipmentNumber = "+ shipmentNumber);
		        System.out.println("ShipmentStatus = "+ shipmentMilestone);
		        System.out.println("ShipmentLocation = "+ shipmentLocation);
//		        System.out.println("ShipmentCompliance = "+ complianceStatus);
		        System.out.println("Create shipment took " + testTimeTakenSec + " seconds.");
	        }
        }
        catch (Exception e) {
        	e.printStackTrace();
        	if (e instanceof InterruptedException) {
        		// Currently ignore exception thrown by "Thread.sleep"
        	}
        	else {
        		// Other exceptions such as certain element not found considered as fail.
        		isPass = "FAIL";
        	}
        }
        finally {
        	String testValue = "Shipment number = "+ shipmentNumber +"\nShipment status = "+ shipmentMilestone;
    	   if (!shipmentMilestone.equalsIgnoreCase("B-CREATE")) {
	          isPass = "FAIL";
	          testValue += "\nExpected shipment status: B-CREATE";
    	   }
    	   else {
         	  isPass = "PASS";     
 	      }
    	   String timeTakenString = null;
    	   if (testTimeTakenSec < epsilon) {
    		   timeTakenString = "-";
    	   }
    	   timeTakenString = String.valueOf(testTimeTakenSec);
        	     
    	 //Print HTML report
           AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Create shipment", isPass, testValue, timeTakenString));
              
                	try {
                		//Print EXCEL report
                		resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP, "Shipment", "Create shipment", isPass, timeTakenString, testValue);
        		
			} 
        	catch (IOException e) {
				e.printStackTrace();
			}
	       
        }
	}
	
	
    
	public void updateShipment() {
		//boolean isPass = true;
		double testTimeTakenSec = 0;
		
		try {
			Thread.sleep(2000);
			//Add Received Date
			driver.findElement(By.id("received_local_datetime")).sendKeys(timeStamp.getReceivedDate());
			driver.findElement(By.id("local_time_RECEIVED")).sendKeys(timeStamp.getReceivedTime());
			
			//Update payment term
			new Select (driver.findElement(By.id("payment_term_code"))).selectByVisibleText(shipmentData.getPaymentTerm());
			wait.until(ExpectedConditions.presenceOfElementLocated(By.className("saveLinkImage"))).click();
			long timeBeforeSave = System.currentTimeMillis();
	        // Wait until shipment status = "RECEIVED"
	        wait.until(new ExpectedCondition<Boolean>(){
    	        @Override
    	        public Boolean apply(WebDriver d) {
    	        	return d.findElement(By.id("SHIPMENT")).getText().equalsIgnoreCase("RECEIVED");
    	    	}
	        });
	        long timeAfterSave = System.currentTimeMillis();
	        testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;
			WebElement mileStoneBoard = driver.findElement(By.id("SHIPMENT"));
			shipmentMilestone = mileStoneBoard.getText();
		}
		catch (Exception e) {
			e.printStackTrace();
        	if (e instanceof InterruptedException) {
        		// Currently ignore exception thrown by "Thread.sleep"
        	}
        	else {
        		// Other exceptions such as certain element not found.
        		isPass = "FAIL";
        	}
		}
		finally {
			String timeTakenString = null;
    		if (testTimeTakenSec < epsilon) {
    			timeTakenString = "-";
    		}
    		else {
    			timeTakenString = String.valueOf(testTimeTakenSec);
    		}
			String testValue = "Shipment status = "+ shipmentMilestone;
			if (!shipmentMilestone.equalsIgnoreCase("RECEIVED")) {
				isPass = "FAIL";
        		testValue += "\nExpected shipment status: RECEIVED";
        	}
			else{
				isPass = "PASS";
			}
				
			try {
				//Print EXCEL report
			resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP, "Shipment", "Update shipment", isPass, timeTakenString, testValue);
	} 
			catch (IOException e) {
				e.printStackTrace();
			}
			
			//Print HTML report
            AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Update shipment", isPass, testValue, timeTakenString));
		}
	}
	
	public void checkCompliance() {
		String isPass = "PASS";
		double testTimeTakenSec = 0;
		//Compliance status
		try {
			
			long timeBeforeSave = System.currentTimeMillis();
			complianceStatus = driver.findElement(By.id("COMP_DNP")).getText();
			long timeAfterSave = System.currentTimeMillis();
			testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;
		}
		catch (Exception e) {
			e.printStackTrace();
        	if (e instanceof InterruptedException) {
        		// Currently ignore exception thrown by "Thread.sleep"
        	}
        	else {
        		// Other exceptions such as certain element not found.
        		isPass = "FAIL";
        	}
		}
		finally {
			String timeTakenString = null;
    		if (testTimeTakenSec < epsilon) {
    			timeTakenString = "-";
    		}
    		else {
    			timeTakenString = String.valueOf(testTimeTakenSec);
    		}
		
			String testValue = "Complicance status = " + complianceStatus;
			if (!complianceStatus.equalsIgnoreCase("DNPPASS")) {
				isPass = "FAIL";
				testValue += "Expected compliance status: DNPPASS";
			}
			else{
				isPass = "PASS";
			}
				
			try {
				//Print EXCEL report
			resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP, "Shipment", "Compliance", isPass, timeTakenString, testValue);
	} 
			catch (IOException e) {
				e.printStackTrace();
			}
			
			//Print HTML report
              AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Compliance", isPass, testValue, timeTakenString));
		}
	}
	
	public void ShipmentRef() throws InterruptedException, IOException{
		
		double testTimeTakenSec = 0;
		String isPass = "PASS";

	    Thread.sleep(3000); 
	    try {
		 wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div[2]/ul[3]/li[2]/a"))).click();
	     Thread.sleep(6000);       
		 WebElement searchdropdown= wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[4]/div/div/form/div/div[3]/div/div/div/form/div/select")));
		 new Select (searchdropdown).selectByVisibleText("ENTRY - IMPORT ENTRY NUMBER");
	     Thread.sleep(2000);            
	     wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div[4]/div/div/form/div/div[3]/div/div/div/form/div[2]/div/textarea"))).sendKeys(shipmentNumber+"H1");
	     Thread.sleep(3000);
	     long timeBeforeSave = System.currentTimeMillis();
       	 driver.findElement(By.xpath("/html/body/div/div[4]/button[3]")).click();
         long timeAfterSave = System.currentTimeMillis(); 
	     testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;
	     ReferenceValue =driver.findElement(By.xpath("/html/body/div[4]/div/div/form/div/div[3]/div/div/div/form/div[2]/div/textarea")).getText();
	     Thread.sleep(3000); 
	      wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div[2]/ul[3]/li/a"))).click();    
	    }
	catch (Exception e) {
    	if (e instanceof InterruptedException) {
    		// Currently ignore exception thrown by "Thread.sleep"
    	}
    	else {
    		// Other exceptions such as certain element not found considered as fail.
    		isPass = "FAIL";
    	}
	}    	
    	finally {
			String timeTakenString = null;
    		if (testTimeTakenSec < epsilon) {
    			timeTakenString = "-";
    		}
    		else {
    			timeTakenString = String.valueOf(testTimeTakenSec);
    		}
    		String testValue = "Reference Value = "+ ReferenceValue;
			if (!ReferenceValue.equalsIgnoreCase(shipmentNumber+"H1")) {
				isPass = "FAIL";
        		testValue += "\nExpected shipment Reference:" +(shipmentNumber+"H1");
        	}
			try {
				//Print EXCEL report
			resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP, "Shipment", "Update References", isPass, timeTakenString, testValue);
		}
		catch (IOException e) {
			e.printStackTrace();
		}
			//Print HTML report
	    AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Update References", isPass, testValue, timeTakenString));
	}
    	}

	
public void addPieceLine() {
		String isPass = "PASS";
		double testTimeTakenSec = 0;
		String cumulativePieces = "";
		
		try {
			Thread.sleep(3000);
//			wait.until(new ExpectedCondition<Boolean>(){
//    	        @Override
//    	        public Boolean apply(WebDriver d) {
//    	        	System.out.println(d.findElements(By.id("spinner")).isEmpty());
//    	        	return d.findElements(By.id("spinner")).isEmpty();
//    	    	}
//	        });
			
//			//Navigate to Pieceline UI to Create Pieceline
			wait.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div/div[2]/ul[3]/li/a"))).click();
//			wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//ul[@id='topLinks']/li[text()='Piece lines']"))).click();
			Thread.sleep(3000);
//			wait.until(new ExpectedCondition<Boolean>(){
//    	        @Override
//    	        public Boolean apply(WebDriver d) {
//    	        	return d.findElements(By.id("spinner")).isEmpty();
//    	    	}
//	        });
			wait.until(ExpectedConditions.presenceOfElementLocated(By.id("customer_stated_count"))).sendKeys(shipmentData.getPackageCount());;
//	        driver.findElement(By.id("customer_stated_count")).sendKeys(shipmentData.getPackageCount());
	        new Select (driver.findElement(By.id("customer_package_type_code"))).selectByVisibleText(shipmentData.getPackageType());
	        driver.findElement(By.id("short_goods_description_details")).sendKeys(shipmentData.getShortDescription());
	        driver.findElement(By.id("customer_length")).sendKeys("10");
	        driver.findElement(By.id("customer_width")).sendKeys("20");
	        driver.findElement(By.id("customer_height")).sendKeys("30");
	        driver.findElement(By.id("customer_weight")).sendKeys("100");
	        //Save Piece line
	        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("btn_pieceline_add"))).click();
	        
	        long timeBeforeSave = System.currentTimeMillis();
	        // Wait until dialog box shows up with proper text
	        wait.until(new ExpectedCondition<Boolean>(){
    	        @Override
    	        public Boolean apply(WebDriver d) {
    	        	return d.findElement(By.className("errString")).getText().equalsIgnoreCase("Pieceline Record Successfully Created");
    	    	}
	        });
	        long timeAfterSave = System.currentTimeMillis();
	        testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;
	        
	        cumulativePieces= driver.findElement(By.id("cumulative_stated_count")).getText();
	       
		}
		catch (Exception e) {
        	if (e instanceof InterruptedException) {
        		// Currently ignore exception thrown by "Thread.sleep"
        	}
        	else {
        		// Other exceptions such as certain element not found considered as fail.
        		isPass = "FAIL";
        	}
		}
		finally 
		{
			String timeTakenString = null;
    		if (testTimeTakenSec < epsilon) {
    			timeTakenString = "-";
    		}
    		else {
    			timeTakenString = String.valueOf(testTimeTakenSec);
    		}
		
			String testValue = "";
			if (cumulativePieces == shipmentData.getBookedPieces()) {
				testValue = "PieceCount = " + cumulativePieces;
				isPass = "PASS";
			}
			else
			{
				isPass = "FAIL";
			}
			
			try {
				//Print EXCEL report
				resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP, "Shipment", "Create Piecelines", isPass, testTimeTakenSec, testValue);
			}
			catch (IOException e) {
				e.printStackTrace();
			}
			//Print HTML report
	         AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Create Pieclines", isPass, testValue, timeTakenString));
		}
	}
	
	public void addCharges(){
		String isPass = "PASS";
		double testTimeTakenSec = 0;
		
		try {
	        //Navigate to ShipmentCharges UI to add Charges
		    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div[2]/ul[3]/li[4]/a"))).click();
			Thread.sleep(13000);
			//Get the AutoRated Charge list
			wait.until(ExpectedConditions.presenceOfElementLocated(By.id("charge_list"))).click();
			wait.until(ExpectedConditions.presenceOfElementLocated(By.id("3__main_div"))).click();
			Thread.sleep(4000);
			//Remove the unwanted charges
			//driver.findElement(By.id("3__remove_view")).click();
			driver.findElement(By.id("4__remove_view")).click();
			driver.findElement(By.id("edit_charges")).click();
			//driver.findElement(By.id("1__charge_code")).sendKeys("8000");
			//WebElement element3 = driver.findElement(By.id("1__charge_code"));
			//element3.sendKeys(Keys.TAB);
			//Thread.sleep(2000);
			// new Select (driver.findElement(By.id("1__payer_account_line_one"))).selectByVisibleText("SHIPTO,CONSIGNEE/109397250-AMPCO METALS");
			driver.findElement(By.id("2__basis")).sendKeys(shipmentData.getShipmentChargeTypeCode());
			WebElement element4 = driver.findElement(By.id("2__basis"));
			element4.sendKeys(Keys.TAB);
			Thread.sleep(2000);
			driver.findElement(By.id("2__rate_amount")).sendKeys(shipmentData.getShipChargeAmount());
			driver.findElement(By.id("2__rate_amount_currency")).sendKeys(shipmentData.getShipChargeCurrencyCode());
			
			driver.findElement(By.id("3__basis")).sendKeys(shipmentData.getShipmentChargeTypeCode());
			WebElement element5 = driver.findElement(By.id("3__basis"));
			element5.sendKeys(Keys.TAB);
			Thread.sleep(2000);
			driver.findElement(By.id("3__rate_amount")).sendKeys(shipmentData.getShipChargeAmount());
			driver.findElement(By.id("3__rate_amount_currency")).sendKeys(shipmentData.getShipChargeCurrencyCode());
			
			driver.findElement(By.id("5__charge_code")).sendKeys("5027");

			driver.findElement(By.id("5__charge_code")).sendKeys(Keys.TAB);
			//driver.findElement(By.xpath("/html/body/div[4]/div/div/div[3]/div[2]/div[3]/ul/div[3]/form/div/li/div/select/option[3]")).click();
			WebElement payerdropdown= wait.until(ExpectedConditions.elementToBeClickable(By.id("5__payer_account_line_one")));
			new Select (payerdropdown).selectByValue(shipmentData.getConsigneePartyAccount());
			payerdropdown.sendKeys(Keys.TAB);
			driver.findElement(By.id("5__basis")).sendKeys("PER IMPORT CLEARANCE");
			WebElement element6 = driver.findElement(By.id("5__basis"));
			element6.sendKeys(Keys.TAB);
			Thread.sleep(3000);
			driver.findElement(By.id("5__rate_amount")).sendKeys(shipmentData.getShipChargeAmount());
			//driver.findElement(By.id("5__rate_amount_currency")).sendKeys(shipmentData.getShipChargeCurrencyCode());
			driver.findElement(By.id("done")).click();
			Thread.sleep(3000);
			
			
			//Saving Shipment Charges
			driver.findElement(By.xpath("/html/body/div/div[4]/button[3]")).click();
			long timeBeforeSave = System.currentTimeMillis();
			 // Wait for success icon
	        wait.until(new ExpectedCondition<Boolean>(){
    	        @Override
    	        public Boolean apply(WebDriver d) {
    	        	return d.findElement(By.className("errString")).getText().equalsIgnoreCase("Charges Saved Succesfully");
    	    	}
	        });
			long timeAfterSave = System.currentTimeMillis();
			testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;
			
			Thread.sleep(4000);
	        
			ratingStatus = driver.findElement(By.id("rating_status_code")).getText();
	        
//	      if (ratingStatus.equalsIgnoreCase("RATED"))
//	   		 
//	   	 {
//	        	isPass = "PASS";
//	   	 }
//	   		 else
//	   		 {
//	   			isPass = "FAIL";
//	   			 }
	       
	}
		catch (Exception e) {
        	e.printStackTrace();
        	if (e instanceof InterruptedException) {
        		// Currently ignore exception thrown by "Thread.sleep"
        	}
        	else {
        		// Other exceptions such as certain element not found considered as fail.
        		isPass = "FAIL";
        	}
        }
		finally {
			String timeTakenString;
    		if (testTimeTakenSec < epsilon) {
    			timeTakenString = "-";
    			
    		}
    		else {
    			timeTakenString = String.valueOf(testTimeTakenSec);
    		}
			String testValue = "Rating status = "+ ratingStatus;
			if (!ratingStatus.equalsIgnoreCase("RATED")) {
        		isPass = "FAIL";
        		testValue += "\nExpected rating status: RATED";
        	}
			
			else{
				isPass = "PASS";
			}
			try 
			{
				//Print EXCEL report
				resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP, "Shipment","Add shipment charges", isPass, testTimeTakenSec, testValue);
				}
				catch (IOException e) {
					e.printStackTrace();
				}
			
			//Print HTML report
		        AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Add Charges", isPass, testValue, timeTakenString));
		}
     }
	
	public void previewInvoice() throws InterruptedException {
        Thread.sleep(8000);
        driver.findElement(By.linkText("Release / Demand")).click();
        Thread.sleep(8000);
        Actions action = new Actions(driver);
        action.moveToElement(driver.findElement(By.xpath("/html/body/div[15]/div[2]/div/div[2]/div[2]/div/div[3]/div[3]/div/table/tbody/tr[2]/td"))).doubleClick().perform();
        Thread.sleep(3000);
        action.moveToElement(driver.findElement(By.xpath("/html/body/div[15]/div[2]/div/div[2]/div[3]/div/div[3]/div[2]/div/table/thead/tr/th/div/input"))).click().perform();
        Thread.sleep(4000);
        //action.moveToElement(driver.findElement(By.linkText("Preview Invoice"))).click().perform();
        //Thread.sleep(12000);
        //getWindows();
        
        //FirefoxProfile firefoxProfile = new FirefoxProfile();
        
        
        /*firefoxProfile.setPreference("browser.download.dir","C:\\Work");
        firefoxProfile.setPreference("browser.download.folderList", 2 );
        firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
        firefoxProfile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf,application/vnd.fdf");

        
        firefoxProfile.setPreference("browser.download.defaultFolder", "C:\\Work");
        firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf,application/octet-stream, application/vnd.fdf, application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff");
        firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
        firefoxProfile.setPreference("pdfjs.disabled", true);

        //Use this to disable Acrobat plugin for previewing PDFs in Firefox (if you have Adobe reader installed on your computer)
        firefoxProfile.setPreference("plugin.scan.Acrobat", "99.0");
        firefoxProfile.setPreference("plugin.scan.plid.all", false);

//Step1: Create a profile or get existing profile
FirefoxProfile ffprofile = new FirefoxProfile();

//Step2: Set preference.
// 0 = desktop, 1 = default download folder , 2 = user defined location.
ffprofile.setEnableNativeEvents(true);
ffprofile.setPreference("browser.download.dir","C:\\Users\\rmanne\\Downloads");
ffprofile.setPreference("browser.download.folderList", 2);


ffprofile.setPreference("plugin.disable_full_page_plugin_for_types","application/zip,application/msword,application/pdf,text/csv,aplication/csv,application/octet-stream");

ffprofile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/x-patch,application/x-jar,application/vnd.android.package-archive,application/zip,application/msword,application/pdf,text/comma-separated-values,text/csv, application/csv, application/excel, application/vnd.ms-excel,application/vnd.msexcel, text/anytext,application/octet-stream");
// WebDriver driver = new FirefoxDriver(ffprofile);
// driver.get();
//driver.findElement(By.linkText("Release / Demand")).click();*/
	}

	public void releaseCharges(){
    //Thread.sleep(5000);
	//boolean isPass = true;
    try
    {
    driver.findElement(By.id("uti-release_demand-charges-release")).click();
    
    Thread.sleep(6000);
        
    long timeBeforeSave = System.currentTimeMillis();

    invoicestatus = driver.findElement(By.xpath("/html/body/div[15]/div[2]/div/div[2]/div[3]/div/div[3]/div[3]/div/table/tbody/tr[2]/td[6]")).getText();
        
    long timeAfterSave = System.currentTimeMillis();
    double testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;
    }
   
    catch (Exception e) {
    	e.printStackTrace();
    	if (e instanceof InterruptedException) {
    		// Currently ignore exception thrown by "Thread.sleep"
    	}
    	else {
    		// Other exceptions such as certain element not found considered as fail.
    		isPass = "FAIL";
    	}
    }
    finally {
		String timeTakenString;
		if (testTimeTakenSec < epsilon) {
			timeTakenString = "-";
			
		}
		else {
			timeTakenString = String.valueOf(testTimeTakenSec);
		}
		 if (invoicestatus == "RELEASED / RATED")
		    {
		          isPass = "PASS";
		    }
		     else
		     {
		    	 isPass = "FAIL";
		     }
      try{
    	//Print EXCEL report
       resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP,"Shipment", "Release charges", isPass, testTimeTakenSec,"InvoiceStaus :" + invoicestatus);
      }
      catch (IOException e) {
			e.printStackTrace();
		}
    //Print HTML report
    AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Release Charges", isPass, "invoicestatus", timeTakenString));
        //Thread.sleep(10000);
      }	
    }

	public void demandCharges(){
		String isPass ="PASS";
	try
	{
        Thread.sleep(9000);
        driver.findElement(By.xpath("/html/body/div[15]/div[2]/div/div[2]/div[2]/div/div[3]/div[3]/div/table/tbody/tr[2]/td")).click();
        Thread.sleep(3000);
        driver.findElement(By.xpath("/html/body/div[15]/div[2]/div/div[2]/div[3]/div/div[3]/div[2]/div/table/thead/tr/th/div/input")).click();
        driver.findElement(By.id("uti-release_demand-charges-demand")).click();
        Thread.sleep(2000);
        driver.findElement(By.id("printer_code")).sendKeys("000000052");
        driver.findElement(By.id("uti-printer-print")).click();
        Thread.sleep(5000);
        driver.findElement(By.id("uti-printer-print")).click();
        Thread.sleep(15000);
        driver.findElement(By.id("uti-release_demand-charges-cancel")).click();
        
                        
        Thread.sleep(16000);
        long timeBeforeSave = System.currentTimeMillis();

        invoicestatus = driver.findElement(By.xpath("/html/body/div[4]/div/div/div[3]/div[2]/div[3]/ul/div/div/li/div/label[11]")).getText();
        
        long timeAfterSave = System.currentTimeMillis();
        double testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;
        Thread.sleep(4000);
	}
        catch (Exception e) {
        	e.printStackTrace();
        	if (e instanceof InterruptedException) {
        		// Currently ignore exception thrown by "Thread.sleep"
        	}
        	else {
        		// Other exceptions such as certain element not found considered as fail.
        		isPass = "FAIL";
        	}
        }
        finally {
    		String timeTakenString;
    		if (testTimeTakenSec < epsilon) {
    			timeTakenString = "-";
    			
    		}
    		else {
    			timeTakenString = String.valueOf(testTimeTakenSec);
    		}

        if (invoicestatus.equalsIgnoreCase("INVOICED RATED"))
       		 
       	 {
       		  isPass = "PASS";
       	 }
       		 else
       		 {
       			 isPass = "FAIL";
       			 }
       
       try
       {
    	 //Print EXCEL report
		resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP,"Shipment", "Demand charges", isPass, testTimeTakenSec,"InvoiceStaus :" + invoicestatus);
        }
        catch (IOException e) {
  			e.printStackTrace();
        }
     //Print HTML report
        AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Create Pieclines", isPass, "invoicestatus", timeTakenString));
        
        //WebElement getShipment = driver.findElement(By.xpath("/html/body/div[4]/div/div/div[2]/div/div/ul/li/span"));
}
        }
	
	public void deliver() {
		String isPass="PASS";
		double testTimeTakenSec = 0;
		
		try {
			//Navigate to Shipment Delivery UI
	        driver.get(bookingUrl);
	        // Search Shipment by shipment Number
	        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("shipment_number"))).sendKeys(shipmentNumber);
	        WebElement element21 = driver.findElement(By.id("shipment_number"));
	        element21.sendKeys(Keys.TAB);
	        Thread.sleep(5000);
	         wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div[2]/ul[3]/li[6]/a"))).click();
//	        Thread.sleep(4000);
	        driver.findElement(By.id("quantity")).sendKeys(shipmentData.getBookedPieces());
	        driver.findElement(By.id("loation_code")).sendKeys("DOOR");
	        driver.findElement(By.id("delivery_datetime")).sendKeys(timeStamp.getDeliverDate());
	        driver.findElement(By.id("time")).sendKeys(timeStamp.getDeliverTime());
	        driver.findElement(By.id("signer_name")).sendKeys("HarryG");
	        driver.findElement(By.id("remark_text")).sendKeys("TESTING");
	        driver.findElement(By.id("delivery_btns")).click();
	        driver.findElement(By.id("add_shipment_delivery")).click();
	        
	        long timeBeforeSave = System.currentTimeMillis();
	        // Wait for success icon
	        wait.until(new ExpectedCondition<Boolean>(){
    	        @Override
    	        public Boolean apply(WebDriver d) {
    	        	return d.findElement(By.className("errStirng")).getText().equalsIgnoreCase("Record Successfully Added");
    	    	}
	        });
	        long timeAfterSave = System.currentTimeMillis();
	        testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;
		}
		catch (Exception e) {
        	if (e instanceof InterruptedException) {
        		// Currently ignore exception thrown by "Thread.sleep"
        	}
        	else {
        		// Other exceptions such as certain element not found considered as fail.
        		isPass = "FAIL";
        	}
        	
        
		}
		finally {
			String timeTakenString = null;
    		if (testTimeTakenSec < epsilon) {
    			timeTakenString = "-";
    		}
    		else {
    			timeTakenString = String.valueOf(testTimeTakenSec);
    		}
			try {
				//Print EXCEL report
				resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP, "Shipment", "Deliver", isPass, timeTakenString);
			}
			catch (IOException e) {
				e.printStackTrace();
			}
			//Print HTML report
		AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Deliver", isPass, "Delivere Shipment", timeTakenString));
		}
	}
	
	public void verifyMilestone(String expectedMileStone) {
		String isPass="PASS";
		double testTimeTakenSec = 0;
		
		try {
			driver.get(bookingUrl);
	        Thread.sleep(4000);
	        // Search Shipment by shipment Number
	        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("shipment_number"))).sendKeys(shipmentNumber);
//            WebElement element18 = driver.findElement(By.id("shipment_number"));
            driver.findElement(By.id("shipment_number")).sendKeys(Keys.TAB);
            Thread.sleep(6000);
	       
	        //Print the updated shipment status
	        shipmentMilestone = driver.findElement(By.id("SHIPMENT")).getText();
	        
	        if (debugMode) {
	        	System.out.println("Shipment status = "+ shipmentMilestone);
	        }
		}
		catch (Exception e) {
			
        	if (e instanceof InterruptedException) {
        		// Currently ignore exception thrown by "Thread.sleep"
        	}
        	else {
        		// Other exceptions such as certain element not found considered as fail.
        		isPass = "FAIL";
        	}
		}
		finally {
			String testValue = "Shipment status = "+ shipmentMilestone;
			if (!shipmentMilestone.equalsIgnoreCase(expectedMileStone)) {
        		isPass = "FAIL";
        		testValue += "\nExpected shipment status: " + expectedMileStone;
        	}
			else{
				isPass="PASS";
			}
			try {
				//Print EXCEL report
				resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP, "Choreography", "Verify shipment status:" + expectedMileStone, isPass, "N/A", testValue);
			}
			catch (IOException e) {
				e.printStackTrace();
			}
			//Print HTML report
	        AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Deliver", isPass, testValue, "N/A"));
		}
	}
	
	public void creditDebitCorrection() throws InterruptedException, IOException{
		double testTimeTakenSec = 0;

		invoiceviewurl = UTiLogin.url+"#!invoice/view";
		invoiceinitiateurl = UTiLogin.url+"#!invoice/monetary";
		correctionchargesurl = UTiLogin.url+"/#!charges/invoice/0";
		        
		        // CorrectionCRDR  crdr = new  CorrectionCRDR(driver, timeStamp );
		        //driver.get(invoiceviewurl);
		        Thread.sleep(8000);
		wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div[4]/div/div")));
		//wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("viewBtn"))).click();
		driver.findElement(By.xpath("/html/body/div[4]/div/div/div[2]/div/div[3]/div[3]/div/table/tbody/tr[2]/td")).click();
		Thread.sleep(5000);
		wait.until(ExpectedConditions.presenceOfElementLocated(By.id("correct_view"))).click();
		Thread.sleep(8000);
		wait.until(ExpectedConditions.presenceOfElementLocated(By.id("search_for_x")));
		Thread.sleep(4000);
		WebElement correctiontypedropdown= wait.until(ExpectedConditions.elementToBeClickable(By.id("correction_type_code")));
		new Select (correctiontypedropdown).selectByVisibleText("CREDIT OR DEBIT");
		Thread.sleep(3000);
		WebElement correctionreasondropdown= wait.until(ExpectedConditions.elementToBeClickable(By.id("reason_code")));
		new Select (correctionreasondropdown).selectByVisibleText("RATING ERROR");
		Thread.sleep(3000);
		driver.findElement(By.id("requester_first_name")).sendKeys("T");
		driver.findElement(By.id("requester_last_name")).sendKeys("J");
		Thread.sleep(3000);
		wait.until(ExpectedConditions.presenceOfElementLocated(By.id("submitContainerForm"))).click();
		Thread.sleep(7000);

		// driver.get(invoiceinitiateurl);

		wait.until(ExpectedConditions.presenceOfElementLocated(By.id("search_for_x"))).click();
		Thread.sleep(4000);
		//driver.switchTo().frame("correction_invoice_request_monetary_invoice");
		// Thread.sleep(2000);
		//action.moveToElement(driver.findElement(By.xpath("/html/body/div[4]/div/div/form[2]/div[2]/div/div[3]/div[3]/div/table/tbody/tr[2]/td"))).doubleClick().build().perform();
		driver.findElement(By.id("change_debtor_invoice_items")).click();
		driver.findElement(By.id("gbox_initiate-correction-grid")).click();
		driver.findElement(By.className("ui-jqgrid-bdiv")).click();
		driver.findElement(By.id("initiate-correction-grid")).click();


		//Thread.sleep(5000);

		//driver.findElement(By.id("charges")).click();
		driver.findElement(By.id("search_for_x")).click();
		driver.findElement(By.id("correction_invoice_request_monetary_invoice")).click();
		driver.findElement(By.id("corrections_billing_transportation_details")).click();
		//driver.switchTo().activeElement();
		//Thread.sleep(2000);
		//driver.findElement(By.xpath("/html/body/div[4]/div/div/form[2]/div[4]/div/div/h3")).click();

		Thread.sleep(2000);
		wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Modify Charges"))).click();
		//driver.findElement(By.id("modify_charges")).click();//frame(driver.findElement(By.xpath("/html/body/div[4]/div/div/form[2]/div[4]/div/div/a")));
		//driver.findElement(By.id("modify_charges")).click();

		// System.out.println("Correction Charges link");
		Thread.sleep(8000);


		//Increase amount in corrections charges screen
		//Thread.sleep(4000);
		wait.until (ExpectedConditions.visibilityOfElementLocated (By.id ("contentBody"))).click(); 
		//driver.get(correctionchargesurl);
		/*driver.findElement(By.id("contentBody")).click();
		//driver.findElement(By.id("controller")).click();
		driver.findElement(By.id("charges")).click();
		driver.findElement(By.id("corrections_billing_transportation_details")).click();
		driver.findElement(By.id("correction_billing_charges_trans_header")).click();
		driver.findElement(By.id("columns correction_billing_charges_header")).click();
		// driver.findElement(By.id("charges")).click();*/
		Thread.sleep(4000);
		driver.findElement(By.xpath("/html/body/div[4]/div/div/div/div[4]/div[2]/div/div[3]/div[3]/div/table/tbody/tr[2]/td[3]")).click();
		//driver.findElement(By.id("transaction_charge_rates_rate_amount_sell")).sendKeys(Keys.CONTROL,'a')));
		Thread.sleep(2000);
		driver.findElement(By.id("transaction_charge_rates_rate_amount_sell")).sendKeys(Keys.chord(Keys.CONTROL, "a"));
		driver.findElement(By.id("transaction_charge_rates_rate_amount_sell")).sendKeys(Keys.CLEAR);
		Thread.sleep(5000);
		driver.findElement(By.id("transaction_charge_rates_rate_amount_sell")).sendKeys("600.45");
		driver.findElement(By.id("transaction_charge_rates_rate_amount_sell")).sendKeys(Keys.TAB);
		Thread.sleep(2000);
		driver.findElement(By.id("costCalculate")).click();
		Thread.sleep(2000);
		driver.findElement(By.id("costUpdate")).click();

		//Save charges correction
		wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/div[4]/button[4]"))).click();
		Thread.sleep(8000);

		//Finalize corrections

		driver.findElement(By.id("cost_close")).click();
		Thread.sleep(4000);
		//driver.findElement(By.id("scrollable_footer")).click();
		// driver.findElement(By.id("scrollable_footer_buttons")).click();

		long timeBeforeSave = System.currentTimeMillis();
		driver.findElement(By.id("finalizeInvoice")).click();

		long timeAfterSave = System.currentTimeMillis();
		testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;
		Thread.sleep(10000);

		//Close Finalize corrections dialogue box

		//  Switch to Dialog box-Finalize
		aLert();


		// wait.until (ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[17]"))).click();
		//driver.findElement(By.id("uti-information-ok")).click();
		Thread.sleep(16000);

		//read Invoice numbers

		Thread.sleep(8000);
		WebElement table = driver.findElement(By.id("grid-search-invoice"));
		invoicenumber = table.findElement(By.xpath("/html/body/div[4]/div/div/form/div[5]/div[2]/div[3]/div[3]/div/table/tbody/tr[2]/td[4]")).getText();
         if (invoicenumber!= null) {
        	 isPass = "PASS";
         }
         
         else{
        	 isPass = "FAIL";
        	 
         }
        	 
        	 
       //Print HTML report
	    AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Invoice Search", isPass, "Invoice Number: " +invoicenumber,"N/A"));
		
		crinvoicenumber = table.findElement(By.xpath("/html/body/div[4]/div/div/form/div[5]/div[2]/div[3]/div[3]/div/table/tbody/tr[3]/td[4]")).getText();

		  if (crinvoicenumber!= null) {
	        	 isPass = "PASS";
	         }
	         
	         else{
	        	 isPass = "FAIL";
	        	 
	         } 
		
		//Print HTML report
		    
		    AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Corrections-CR-DR", isPass, "crinvoicenumber: " +crinvoicenumber, "N/A"));

		
		//resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP,"Shipment", "Invoice Search", true, testTimeTakenSec,"InvoiceNumber :" + invoicenumber);
		//resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP,"Shipment", "Correction CR-DR", true, testTimeTakenSec ,"Correction InvoiceNumber :" + crinvoicenumber); 
		Thread.sleep(1000);
		System.out.println("Invoice Number = "+ invoicenumber);
		System.out.println("Corrections Invoice Number = "+ crinvoicenumber);
		}

	public void aLert()
	{
		boolean a = false;
		try {
			Alert alert = driver.switchTo().alert();
			String AlertText = alert.getText();
			System.out.println(AlertText);
			alert.accept();
			a = true;
		} 
		catch (Exception e) {
			a = false;
		}
		finally {
			if (a != true) {
				// take ur screenshot or whatever
				driver.findElement(
				By.id("uti-information-ok")).click();
			}
		}
	}
	
	public void invoiceSearch() throws InterruptedException, IOException{
        
		invoicesearchurl = UTiLogin.url+"#!invoice/search";
		        
        // CorrectionCRDR  crdr = new  CorrectionCRDR(driver, timeStamp );
        driver.get(invoicesearchurl);
        Thread.sleep(3000);       
        WebElement searchdropdown= wait.until(ExpectedConditions.elementToBeClickable(By.id("select_search_type")));
		new Select (searchdropdown).selectByVisibleText("SHIPMENT NUMBER");
		Thread.sleep(7000);               
		wait.until(ExpectedConditions.presenceOfElementLocated(By.id("transaction_type_business_number"))).sendKeys(shipmentNumber);
		//WebElement element21 = driver.findElement(By.id("shipment_number"));
		//element21.sendKeys(Keys.TAB);
		Thread.sleep(8000);
		long timeBeforeSave = System.currentTimeMillis();

		driver.findElement(By.id("btnSearch")).click();

		long timeAfterSave = System.currentTimeMillis();
		double testTimeTakenSec = (timeAfterSave - timeBeforeSave) / 1000.0;

		Thread.sleep(2000);
		driver.findElement(By.xpath("/html/body/div[4]/div/div/form/div[5]/div[2]/div[3]/div[3]/div/table/tbody/tr[2]/td[2]")).click();
		wait.until(ExpectedConditions.presenceOfElementLocated(By.id("viewBtn"))).click();
		Thread.sleep(8000);
		
	}

//		            WebElement invoiceclass = driver.findElement(By.className("ui-jqgrid-bdiv"));
		        //            invoicenumber = invoiceclass.findElement(By.xpath("/html/body/div[4]/div/div/form/div[5]/div[2]/div[3]/div[3]/div/table/tbody/tr[2]/td[4]")).getText();
		//   Thread.sleep(8000);
		//   resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP,"Shipment", "Invoice Search", true, "0","InvoiceNumber :" + invoicenumber);
		
		public void verifyShipmentPo() throws InterruptedException, IOException{
			
			
			Thread.sleep(9000);
						
			driver.findElement(By.xpath("/html/body/div[4]/div/div/div[3]/div[2]/div[3]/ul/div/div/li/div/label/a")).click();

			//Thread.sleep(4000);
			
			shpmtChargeDetails();
			
			System.out.println("PO time stamp" + shippotimestamp);
			
			
			
			String testValue= "shipment PO number  = "+shipmentNumber +"R1";
			if ( shippotimestamp !=null )
			{ 
				isPass = "PASS";
			
			}
			
			else if ( shippotimestamp == " " )
			{
				isPass = "FAIL";
			}
			
			//Print HTML report
		    AirSmokeTest.RESULT_ARRAY.add(new Results("Shipment", "Verify Shipment PO", isPass, testValue, "N/A"));
			resultSheet.writeTestStepResult(++AirSmokeTest.TESTSTEP, "Movement", "Verify Movement PO", isPass, testTimeTakenSec, testValue);
		
		    
		   Thread.sleep(4000);
		}
			
		

		public void shpmtChargeDetails() throws InterruptedException
		{
		    boolean a = false;
		    try {
		        Alert alert = driver.switchTo().alert();
		        String AlertText = alert.getText();
		        System.out.println(AlertText);
		        alert.accept();
		        a = true;
		    } catch (Exception e) {
		        a = false;
		    }finally {
		        if (a != true) {
		        	 if (a != true) {
		 	        	
		 	        	driver.findElement(By.xpath("/html/body/div[15]/div[2]/div/ul/li[3]/a")).click();
		 	            // take ur screenshot or whatever
		 	        	shippotimestamp=  driver.findElement(By.id("initial_po_sent_timestamp")).getText();
		 	        }
		    }

		    }
		}
	
	public String getShipmentNumber() {
		return this.shipmentNumber;
	}
	
	public String getShipemntMilestone() {
		return this.shipmentMilestone;
	}
	
	public String getBuildLabel(){
		return this.buildlabel;
	}
	
	public String getEnvName(){
		return this.envname;
	}

}
